function ajax(type, url) {
  return new Promise((resolve, reject) => {
    let xhr = new XMLHttpRequest();
    xhr.open(type, url);
    xhr.send();
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) { //响应完成
        if (xhr.status == 200) { //响应成功
          let resData = xhr.responseText;
          resolve(resData) //写到resolve里的实参是会传个then方法的
        } else {
          reject();
        }
      }
    }
  })

}